package com.supersit.GZFDA.activity;

import java.util.List;

import com.supersit.GZFDA.R;
import com.supersit.GZFDA.adapter.BusinessListAdapter;
import com.supersit.GZFDA.app.MyApp;
import com.supersit.GZFDA.entity.Business;
import com.supersit.GZFDA.util.AppManager;
import com.zhy.autolayout.AutoLayoutActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class SearchDataListActivity extends AutoLayoutActivity {
	private ListView lvSearchDataList;
	private List<Business> Businesss;
	private BusinessListAdapter adapter;
	private Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search_data);
		AppManager.getAppManager().addActivity(SearchDataListActivity.this);
		context = this;
		lvSearchDataList = (ListView) findViewById(R.id.lv_search_data);
		getIntentData();
		bindListener();

	}

	@SuppressWarnings("unchecked")
	private void getIntentData() {
		Businesss = MyApp.getInstance().getBusinesss();
		adapter = new BusinessListAdapter(Businesss, context);
		lvSearchDataList.setAdapter(adapter);

	}

	private void bindListener() {
		lvSearchDataList.setOnItemClickListener(onItemClickListener);
	}

	private OnItemClickListener onItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent = new Intent(context, MainActivity.class);
			Bundle bundle = new Bundle();
			bundle.putSerializable("Business", Businesss.get(arg2));
			intent.putExtras(bundle);
			startActivity(intent);

		}
	};

	// 返回键的重写
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK
				&& event.getAction() == KeyEvent.ACTION_DOWN) {
			AppManager.getAppManager().finishActivity(
					SearchDataListActivity.this);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
